package com.swak.registry;

import java.util.List;
import java.util.Map;

import com.swak.Constants;
import com.swak.utils.Maps;

public class DispatchWorker implements NotifyListener {

	URL url;
	URL subscribeUrl;
	Registry registry;

	public DispatchWorker(Registry registry) {
		this.registry = registry;
		Map<String, String> parameters = Maps.newHashMap();
		parameters.put(Constants.Application_KEY, "Job");
		parameters.put(Constants.Service_Key, "WechatJob");
		parameters.put(Constants.Category_Key, "Dispatcher");
		url = new URL("job", "127.0.0.1", 0, "/worker", parameters);

		this.registry.register(url);
		parameters = Maps.newHashMap();
		parameters.put(Constants.Application_KEY, "Job");
		parameters.put(Constants.Service_Key, "WechatJob");
		parameters.put(Constants.Category_Key, "Executor");
		subscribeUrl = new URL("job", "127.0.0.1", 0, "/worker", parameters);
		this.registry.subscribe(subscribeUrl, this);
	}

	@Override
	public void notify(List<URL> urls) {
		System.out.println("Url 地址的变化：" + urls);
	}
}